//
//  LoginNumberView.m
//  Project_IOS
//
//  Created by Jeff on 2022/1/11.
//

#import "LoginNumberView.h"
#import <Masonry/Masonry.h>
#import "Color.h"
@interface LoginNumberView ()



@property (nonatomic, strong) UIButton *clearBtn;
@property (nonatomic, strong) UIView *contentView;

@property (nonatomic, strong) UIView *textView;

@property (nonatomic, assign) BOOL isphone;
@property (nonatomic, assign) BOOL isShow;

@end

@implementation LoginNumberView


- (instancetype)initPhone:(BOOL)isPhone {
    self = [super init];
    if (self) {
        self.isphone = isPhone;
        self.isShow = false;
        [self creatUI];
    }
    return self;
}

- (instancetype)init {
    self = [super init];
    if (self) {
        [self creatUI];
    }
    return self;
}

- (void)creatUI {
    [self addSubview:self.contentView];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(311, 52));
        make.top.left.mas_equalTo(0);
    }];
    
    [self.contentView addSubview:self.textField];
    
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.mas_equalTo(82));
//        make.centerX.mas_equalTo(0);
        make.left.mas_equalTo(20);
            make.right.mas_equalTo(-40);
            make.centerY.mas_equalTo(0);
    }];
    
    [self.contentView addSubview:self.clearBtn];
    [self.clearBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(20, 20));
            make.centerY.mas_equalTo(0);
            make.right.mas_equalTo(-16);
    }];
    
}

- (UIView *)contentView {
    if (!_contentView) {
        _contentView = [[UIView alloc] init];
        _contentView.backgroundColor = [Color colorWithHexString:@"#F7F7F7"];
        _contentView.layer.cornerRadius = 26;
        _contentView.layer.masksToBounds = true;
        
    }
    return _contentView;
}

//- (UIView *)textView {
//    if (!_textView) {
//        _textView = [[UIView alloc] init];
//        _textView.backgroundColor = [Color colorWithHexString:@"#F7F7F7"];
//        _textView.layer.cornerRadius = 26);
//        _textView.layer.masksToBounds = true;
//
//    }
//    return _textView;
//}

- (UITextField *)textField {
    if (!_textField) {
        _textField = [[UITextField alloc] init];
        _textField.textColor = [Color colorWithHexString:@"#333333"];
        _textField.font = [UIFont systemFontOfSize:16];
        _textField.textAlignment = NSTextAlignmentLeft;
        if (self.isphone) {
            _textField.placeholder = @"请输入手机号";
            _textField.keyboardType = UIKeyboardTypeNumberPad;
        }else{
            _textField.secureTextEntry = true;
            _textField.placeholder = @"请输入密码";
        }
    }
    return _textField;
}

- (UIButton *)clearBtn {
    if (!_clearBtn) {
        _clearBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        if (self.isphone) {
            [_clearBtn setBackgroundImage:[UIImage imageNamed:@"login_clear.png"] forState:UIControlStateNormal];
            [_clearBtn addTarget:self action:@selector(clearTarget) forControlEvents:UIControlEventTouchUpInside];
        }else{
            [_clearBtn setBackgroundImage:[UIImage imageNamed:@"login_eye.png"] forState:UIControlStateNormal];
            [_clearBtn addTarget:self action:@selector(showSecure) forControlEvents:UIControlEventTouchUpInside];
        }
    }
    return _clearBtn;
}


- (void)clearTarget {
    _textField.text = @"";
}

- (void)showSecure {
    self.isShow = !self.isShow;
    
    if (self.isShow) {
        _textField.secureTextEntry = false;
    }else{
        _textField.secureTextEntry = true;
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
